package com.nbsaas.boot.duckdb;

import java.sql.*;

public class DuckDBMySQLExample {
    public static void main(String[] args) throws Exception {
        // DuckDB 本地数据库
        Class.forName("org.duckdb.DuckDBDriver");
        Connection conn = DriverManager.getConnection("jdbc:duckdb:./data/duckdb.db");
        Statement stmt = conn.createStatement();

        // 启用 MySQL 插件
        stmt.execute("INSTALL mysql");
        stmt.execute("LOAD mysql");

        // 连接 MySQL
        stmt.execute("ATTACH 'mysql://root:123.com@localhost:3306/baison-erp' AS mydb (TYPE mysql)");

        // 查询 MySQL 数据
        ResultSet rs = stmt.executeQuery("SELECT * FROM mydb.user_info LIMIT 5");
        while (rs.next()) {
            System.out.println(rs.getInt("id") + " - " + rs.getString("name"));
        }
    }
}
